{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "recognized-majority",
   "metadata": {},
   "source": [
    "# Decision Rule\n",
    "\n",
    "*See the backing repository for Skope Rules [here](https://github.com/scikit-learn-contrib/skope-rules).*\n",
    "\n",
    "## Summary\n",
    "\n",
    "Decision rules are logical expressions of the form `IF ... THEN ...`. Interpret's implementation uses a wrapped variant of `skope-rules`{cite}`skrules_2017`, which is a weighted combination of rules extracted from a tree ensemble using L1-regularized optimization over the weights. Rule systems, like single decision trees, can give interpretability at the cost of model performance. These discovered decision rules are often integrated into expert-driven rule-based systems.\n",
    "\n",
    "## How it Works\n",
    "\n",
    "The creators of skope-rules have a lucid synopsis of what decision rules are [here](https://github.com/scikit-learn-contrib/skope-rules).\n",
    "\n",
    "Christoph Molnar's \"Interpretable Machine Learning\" e-book {cite}`molnar2020interpretable` has an excellent overview on decision rules that can be found [here](https://christophm.github.io/interpretable-ml-book/rules.html).\n",
    "\n",
    "For implementation specific details, see the skope-rules GitHub repository [here](https://github.com/scikit-learn-contrib/skope-rules).\n",
    "\n",
    "## Code Example\n",
    "\n",
    "The following code will train an skope-rules classifier for the breast cancer dataset. The visualizations provided will be for both global and local explanations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "alone-journalism",
   "metadata": {},
   "outputs": [],
   "source": [
    "from interpret import set_visualize_provider\n",
    "from interpret.provider import InlineProvider\n",
    "set_visualize_provider(InlineProvider())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "august-klein",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn.datasets import load_breast_cancer\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "from interpret.glassbox import DecisionListClassifier\n",
    "from interpret import show\n",
    "\n",
    "seed = 42\n",
    "np.random.seed(seed)\n",
    "X, y = load_breast_cancer(return_X_y=True, as_frame=True)\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=seed)\n",
    "\n",
    "dl = DecisionListClassifier(random_state=seed)\n",
    "dl.fit(X_train, y_train)\n",
    "\n",
    "dl_global = dl.explain_global()\n",
    "show(dl_global)\n",
    "\n",
    "dl_local = dl.explain_local(X_test[:5], y_test[:5])\n",
    "show(dl_local, 0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "varying-powell",
   "metadata": {},
   "source": [
    "## Further Resources\n",
    "\n",
    "- [Skope Rules Documentation](https://skope-rules.readthedocs.io/en/latest/)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "mexican-philadelphia",
   "metadata": {},
   "source": [
    "## Bibliography\n",
    "\n",
    "```{bibliography} references.bib\n",
    ":style: unsrt\n",
    ":filter: docname in docnames\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "mexican-mountain",
   "metadata": {},
   "source": [
    "## API\n",
    "\n",
    "### DecisionListClassifier\n",
    "\n",
    "```{eval-rst}\n",
    ".. autoclass:: interpret.glassbox.DecisionListClassifier\n",
    "   :members:\n",
    "   :inherited-members:\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "underlying-flood",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
